let jsonws = new WebSocket('ws:localhost:3344');
let fs = require('fs');
let deviceMac;
import {WebSocketConfig} from "./WebsocketConfig";

setTimeout(() => {

    fs.readdir('C:/Users/90919/Desktop/home-work/JSON', (err, files) => {
        if (err) {
            console.log(err)
        }
        files.slice(25).forEach((cur, index) => {
            // return;
            // if (cur != '0x00 0x00 0x00 0x00 0x03 0x3e.json') return;
            // deviceMac = WebSocketConfig.macStringfy(cur.slice(0,-5).split(' '));
            console.log(cur);
            setTimeout(() => {

                deviceMac = cur.slice(0, -5).split(' ');
                console.log(deviceMac, 'deviceMac');
                fs.readFile('C:/Users/90919/Desktop/home-work/JSON/' + cur, {encoding: 'utf-8'}, (err, data) => {
                    if (err) throw err;
                    data.split('{"b-history-stroke"')
                        .forEach((value) => {
                            jsonws.send('{"b-history-stroke"'+value);
                        })
                    // console.log(
                    //     data.split('{"b-history-stroke"').length)
                });

            }, index * 100000);
        })
    }, {withFileTypes: true});
}, 10000);
let itag =0;
jsonws.onmessage = function (res) {
    console.log('itag',itag++);
    try {
        WebSocketConfig.getHandle(0x3)({"pen-mac-addr": deviceMac, para: JSON.parse(res.data)})
    } catch (e) {
        console.log(e)
    }
};
